package exercise;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @classname:MD5demo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/12 10:33
 * @version: 0.1
 * @since:1.8
 */
public class MD5demo {
    private static final String  ENGCODE = "UTF-8";
    public static void main(String[] args) {
        String str = "1234";
        System.out.println(encodeStr(str));
    }

    private static String encodeStr(String str) {
      MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        messageDigest.update(str.getBytes(Charset.forName(ENGCODE)));
        byte[] digest = messageDigest.digest();
        return new BigInteger(1,digest).toString(16).toUpperCase();
    }
}
